package com.xing.fragment;

import com.xing.questionnairesurvey.R;
import com.xing.util.AccessUrl;
import com.xing.util.CurrentUserUtil;
import com.xing.util.SharedPreferenceUtil;
import com.xing.util.ViewUtil;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class SettingFragment extends SuperFragment {

	private EditText hostIPEditText,portEditText;
	private Button modifyServerBtn,modifyPwdBtn;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		return (view = inflater.inflate(R.layout.settging_fragment, container, false));
	}
	
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		userNameTextView = (TextView) view.findViewById(R.id.user_name);
		userNameTextView.setText(CurrentUserUtil.userName+",欢迎使用!");
		initWidgets();
	}
	
	private void initWidgets(){
		
		hostIPEditText = (EditText) view.findViewById(R.id.ip_address);
		portEditText = (EditText) view.findViewById(R.id.port);
		modifyServerBtn = (Button) view.findViewById(R.id.modify_server);
		modifyPwdBtn = (Button) view.findViewById(R.id.modify_pwd);
		modifyPwdBtn.setOnClickListener(onMyClickListener);
		modifyServerBtn.setOnClickListener(onMyClickListener);
		
		String hostIp = SharedPreferenceUtil.getStringInfo(getActivity(),SharedPreferenceUtil.HOST_IP);
	    String port = SharedPreferenceUtil.getStringInfo(getActivity(), SharedPreferenceUtil.PORT);
	    if (!(TextUtils.isEmpty(hostIp) && TextUtils.isEmpty(port))) {
			hostIPEditText.setText(hostIp);
			portEditText.setText(port);
		}
	}
	
	private View.OnClickListener onMyClickListener = new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.modify_server:
//				String hostIp = hostIPEditText.getText().toString().trim();
//				String port = portEditText.getText().toString().trim();
//				if (!(TextUtils.isEmpty(hostIp) && TextUtils.isEmpty(port))) {
//					SharedPreferenceUtil.putStringInfo(getActivity(),SharedPreferenceUtil.HOST_IP,hostIp);
//					SharedPreferenceUtil.putStringInfo(getActivity(),SharedPreferenceUtil.PORT,port);
//					ViewUtil.showToast(getActivity(), "保存成功");
//				}else {
//					ViewUtil.showToast(getActivity(), "服务器地址或端口号不能为空");
//				}
				
				break;
			case R.id.modify_pwd:
				
				
				ViewUtil.showToast(getActivity(), "保存成功");
				break;
			default:
				break;
			}
		}
	};
	
}
